/*
 * Copyright (c) 2001-2006 Accenture LLC.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Accenture. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Accenture.
 *
 * ACCENTURE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ACCENTURE
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package org.tigris.jelements;

import org.tigris.mappedlexer.validator.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author zhisen.huang
 * 
 */
public class ElementProduction extends AbstractProduction {

	protected static Log logger = LogFactory.getLog(ElementProduction.class);

	protected Validator modifierValidator = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tigris.javaclue.Production#parse()
	 */
	public void parse() throws Exception {
		StringBuffer buff = new StringBuffer();

		tk = lexer.nexttok(VerifyHub.IDENTIFIER);
		while (modifierValidator.validate(tk)) {
			tk = lexer.nexttok(VerifyHub.IDENTIFIER); // return type
		}
		tk = lexer.nexttok(new String[]{"["}, new Validator[]{VerifyHub.IDENTIFIER}); // method name
		if(tk.equals("[")) {
			tk = lexer.skipTo('[');
			buff.append(tk);
			lexer.nexttok(VerifyHub.IDENTIFIER); // method name
		}
		buff.append(tk);
		tk = lexer.nexttok("(", ";", "=");
		if (tk.equals("(")) {
			tk = lexer.skipTo('('); // parameter list
			buff.append(tk);
			lexer.forwardUntil("{");
			lexer.backward("{");
			tk = lexer.nexttok("{");
			tk = lexer.skipTo('{');
			logger.info("method: " + buff);
		} else {
			if(tk.equals("=")) {
				lexer.forwardUntil(";");
			}
			logger.info("variable: " + buff); // variable
		}
	}

	/**
	 * @param modifierValidator the modifierValidator to set
	 */
	public void setModifierValidator(Validator modifierValidator) {
		this.modifierValidator = modifierValidator;		
	}

}
